const setCookie = function (name, value, expiredays) {
    let exdate = new Date()
    exdate.setDate(exdate.getDate() + expiredays)
    document.cookie = name + '=' + value + ((expiredays == null) ? '' : ';expires=' + exdate.toGMTString())
}
const getCookie = function (name) {
    let allcookies = document.cookie
    let cookiePos = allcookies.indexOf(name + '=')
    if (cookiePos !== -1) {
        cookiePos += name.length + 1
        let cookieEnd = allcookies.indexOf(';', cookiePos)
        if (cookieEnd === -1) {
            cookieEnd = allcookies.length
        }
        // let value = unescape(allcookies.substring(cookiePos, cookieEnd))
        let value = allcookies.substring(cookiePos, cookieEnd)
        return value
    } else {
        return null
    }
}
const delCookie = function (name) {
    var exp = new Date()
    exp.setTime(exp.getTime() - 1)
    var cval = getCookie(name)
    if (cval !== null) {
        document.cookie = name + '=;expires=' + exp.toGMTString()
    }
}
export {
    setCookie,
    getCookie,
    delCookie
}
